package com.xugou.service.Impl;

import com.xugou.dao.OrderDao;
import com.xugou.pojo.Order;
import com.xugou.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.List;

/**
 * @author xugou
 * @date 2022/5/7  22:51
 */

public class OrderServiceImpl implements OrderService {

    private OrderDao orderDao;

    public void setOrderDao(OrderDao orderDao) {
        this.orderDao = orderDao;
    }

    //获取全部订单信息
    public List<Order> getAllOrders() {

        List<Order> orderList = orderDao.getAllOrder();
        if (orderList!=null){
            return orderList;
        }
        return null;
    }

    //通过id获取订单信息
    public Order getOrderInfoById(int id) {

        Order resOrder = orderDao.getOrderById(id);
        if (resOrder!=null){
            return resOrder;
        }
        return null;

    }

    //新增订单信息，成功true，错误false
    public boolean isAddOrder(Order order) {

        int flag = orderDao.addOrder(order);
        if (flag>0){
            return true;
        }
        return false;
    }

    //是否删除订单，成功true，错误false
    public boolean isDeleteOrder(int id) {

        int flag = orderDao.deleteOrderById(id);
        if (flag >0){
            return true;
        }
        return false;
    }

    public List<Order> getOrderInfoByClientId(int id) {
        List<Order> orderList = orderDao.getOrderByClientId(id);
        if (orderList==null){
            return null;
        }
        return orderList;
    }

    public long getOrderNums() {
        long orderNums = orderDao.getOrderNums();
        return orderNums;
    }

    public boolean updateOrderInfo(Order order) {

        int flag = orderDao.updateOrder(order);
        if (flag >0){
            return true;
        }
        return false;
    }
}
